package cn.iocoder.yudao.module.wengfu.controller.admin.resultsdispatchroomdetails;

import cn.iocoder.yudao.module.wengfu.framework.excel.core.util.ExcelUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wengfu.controller.admin.resultsdispatchroomdetails.vo.*;
import cn.iocoder.yudao.module.wengfu.dal.dataobject.resultsdispatchroomdetails.ResultsDispatchRoomDetailsDO;
import cn.iocoder.yudao.module.wengfu.service.resultsdispatchroomdetails.ResultsDispatchRoomDetailsService;

@Tag(name = "管理后台 - 全分析结果统计＿调度室_明细")
@RestController
@RequestMapping("/wengfu/results-dispatch-room-details")
@Validated
public class ResultsDispatchRoomDetailsController {

    @Resource
    private ResultsDispatchRoomDetailsService resultsDispatchRoomDetailsService;

    @PostMapping("/create")
    @Operation(summary = "创建全分析结果统计＿调度室_明细")
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:create')")
    public CommonResult<String> createResultsDispatchRoomDetails(@Valid @RequestBody ResultsDispatchRoomDetailsSaveReqVO createReqVO) {
        return success(resultsDispatchRoomDetailsService.createResultsDispatchRoomDetails(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新全分析结果统计＿调度室_明细")
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:update')")
    public CommonResult<Boolean> updateResultsDispatchRoomDetails(@Valid @RequestBody ResultsDispatchRoomDetailsSaveReqVO updateReqVO) {
        resultsDispatchRoomDetailsService.updateResultsDispatchRoomDetails(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除全分析结果统计＿调度室_明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:delete')")
    public CommonResult<Boolean> deleteResultsDispatchRoomDetails(@RequestParam("id") String id) {
        resultsDispatchRoomDetailsService.deleteResultsDispatchRoomDetails(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除全分析结果统计＿调度室_明细")
                @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:delete')")
    public CommonResult<Boolean> deleteResultsDispatchRoomDetailsList(@RequestParam("ids") List<String> ids) {
        resultsDispatchRoomDetailsService.deleteResultsDispatchRoomDetailsListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得全分析结果统计＿调度室_明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:query')")
    public CommonResult<ResultsDispatchRoomDetailsRespVO> getResultsDispatchRoomDetails(@RequestParam("id") String id) {
        ResultsDispatchRoomDetailsDO resultsDispatchRoomDetails = resultsDispatchRoomDetailsService.getResultsDispatchRoomDetails(id);
        return success(BeanUtils.toBean(resultsDispatchRoomDetails, ResultsDispatchRoomDetailsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得全分析结果统计＿调度室_明细分页")
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:query')")
    public CommonResult<PageResult<ResultsDispatchRoomDetailsRespVO>> getResultsDispatchRoomDetailsPage(@Valid ResultsDispatchRoomDetailsPageReqVO pageReqVO) {
        PageResult<ResultsDispatchRoomDetailsDO> pageResult = resultsDispatchRoomDetailsService.getResultsDispatchRoomDetailsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ResultsDispatchRoomDetailsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出全分析结果统计＿调度室_明细 Excel")
    @PreAuthorize("@ss.hasPermission('wengfu:results-dispatch-room-details:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportResultsDispatchRoomDetailsExcel(@Valid ResultsDispatchRoomDetailsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ResultsDispatchRoomDetailsDO> list = resultsDispatchRoomDetailsService.getResultsDispatchRoomDetailsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "全分析结果统计＿调度室_明细.xls", "数据", ResultsDispatchRoomDetailsRespVO.class,
                        BeanUtils.toBean(list, ResultsDispatchRoomDetailsRespVO.class));
    }
}
